import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;

public class File {
	
	private int fileTag;
	private int fileId;
	private boolean read = false;
	private boolean write = false;
	private boolean create = false;
	private boolean exists = false;
	private boolean exclusive = false;
	private boolean shared = false;
	private Hashtable<FileFlagEnum, Boolean> fileFlagHashMap;
	
	public enum FileFlagEnum{ READ, WRITE, CREATE, EXISTS, EXCLUSIVE, SHARED; }
	
	public File(List<Integer> fileFlags) {
		fileFlagHashMap = new Hashtable<FileFlagEnum, Boolean>();
		
		for (Integer flag : fileFlags) {
			if (flag == OperatingSystem.FileIO.read) {
				read = true; 
				fileFlagHashMap.put(FileFlagEnum.READ, read);				
			} else if (flag == OperatingSystem.FileIO.write) {
				write = true;
				fileFlagHashMap.put(FileFlagEnum.WRITE, write);				
			} else if (flag == OperatingSystem.FileIO.create) {
				create = true;
				fileFlagHashMap.put(FileFlagEnum.CREATE, create);				
			} else if (flag == OperatingSystem.FileIO.exists) {					
				exists = true;
				fileFlagHashMap.put(FileFlagEnum.EXISTS, exists);				
			} else if (flag == OperatingSystem.FileIO.exclusive) {
				exclusive = true;
				fileFlagHashMap.put(FileFlagEnum.EXCLUSIVE, exclusive);				
			} else if (flag == OperatingSystem.FileIO.shared) {
				shared = true;
				fileFlagHashMap.put(FileFlagEnum.SHARED, shared);				
			}	
		}	
	}

	public int getFileTag() {
		return fileTag;
	}

	public void setFileTag(int fileTag) {
		this.fileTag = fileTag;
	}

	public int getFileId() {
		return fileId;
	}

	public void setFileId(int fileId) {
		this.fileId = fileId;
	}
	
	public boolean isRead() {
		return read;
	}

	public boolean isWrite() {
		return write;
	}

	public boolean isCreate() {
		return create;
	}

	public boolean isExists() {
		return exists;
	}

	public boolean isExclusive() {
		return exclusive;
	}

	public boolean isShared() {
		return shared;
	}
	
	/**
	 * Returns how many flags are set to true for this file.
	 * @return
	 */
	public int getFileFlagSetCount() {
		Enumeration<Boolean> e = this.fileFlagHashMap.elements();
		int fileSetTrueCount = 0;
		while (e.hasMoreElements()) {
			if (e.nextElement() == true) {
				fileSetTrueCount++;
			}			
		}
		return fileSetTrueCount;
	}
		
}
